//
//  XiaoximenVoteTime.m
//  Xiaoximen_iOS
//
//  Created by Wang Zhongyu on 12-7-19.
//  Copyright (c) 2012年 Peking University. All rights reserved.
//

#import "XiaoximenVoteTime.h"

@implementation XiaoximenVoteTime
@synthesize party, ID, startDate, endDate, displayDay, displayTimeInterval, totalVote, yesVote, noVote;
@synthesize yesPersons = _yesPersons;
@synthesize noPersons = _noPersons;

- (id)initWithStartDate:(NSDate *)start
				endDate:(NSDate *)end
				 timeID:(NSUInteger)timeID
{
	self = [super init];
	if (self) {
        // Custom initialization
		
		startDate = start;
		endDate = end;
		ID = timeID;

		/*
		//取得國際時間的timeZone，我叫這個時區為sourceTimeZone
		NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
		//取得當地的時區，我稱為destinationTimeZone
		NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
		//算出國際時間的時區，和原本時間的時區差了多少，記錄在sourceGMTOffset
		NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:startDate];
		//算出當地際時間的時區，和原本時間的時區差了多少，記錄在destinationGMTOffset
		NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:startDate];
		//在算出兩者的差距
		NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
		//依差距，把原本以國際標準時間存成的NSDate，轉成新的NSDate
		startDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:startDate];
		endDate = [endDate dateByAddingTimeInterval:interval];
		*/
		
		NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
		formatter.dateFormat = @"yyyy年MM月dd日";
		displayDay = [NSString stringWithFormat:@"%@",[formatter stringFromDate:startDate]];
		formatter.dateFormat = @"hh:00";
		displayTimeInterval = [NSString stringWithFormat:@"%@-%@", [formatter stringFromDate:startDate], [formatter stringFromDate:self.endDate]];
		
		totalVote = yesVote = noVote = 0;
	}
	return self;
}
- (NSMutableArray *)yesPersons
{
	if (_yesPersons == nil) {
		_yesPersons = [[NSMutableArray alloc] init];
	}
	return _yesPersons;
}
- (NSMutableArray *)noPersons
{
	if (_noPersons == nil) {
		_noPersons = [[NSMutableArray alloc] init];
	}
	return _noPersons;
}

@end
